package com.infosys.cabplanning.service.viewTrip;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicLong;

import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.google.gson.Gson;
import com.infosys.cabplanning.common.domain.Driver;
import com.infosys.cabplanning.helper.JsonFormatter;

@Controller
public class ViewTripController {

    private static final String template = "Hello, %s!";
    private final AtomicLong counter = new AtomicLong();

   // @Autowired
   // public DriverDAO viewTripDAO;
    
    @Autowired
    JsonFormatter jsonFormatter;
    
    @RequestMapping(value="viewTrip", method = RequestMethod.POST,produces="application/json",consumes="application/json")
    public @ResponseBody List<Driver> viewTrip(@RequestBody Driver viewTrip) throws Exception {
    		System.out.println("Entered Drivers method");
    		//viewTripDAO.saveTest(30);	
    		//Driver viewTrip = new Driver();
    		viewTrip.setDriverId(123);
    		viewTrip.setDrivingLicenseNumber("asd");
    		
    		List list = new ArrayList();
    		list.add(viewTrip); 
    		String json = new Gson().toJson(list);
    		//System.out.println(json);
    		
		 return list; 
    }
    
    @RequestMapping(value="saveviewTrip", method = RequestMethod.POST ,produces="application/json",consumes="application/json")
    public @ResponseBody List<Object> saveviewTrip(@RequestBody String json) throws Exception {
    		System.out.println("Entered Drivers method");
    		
    		List<Object> list = jsonFormatter.convertToList(json, new Driver());
    		
    		//viewTripDAO.saveTest(30);	
    		Driver viewTrip = new Driver();
    		viewTrip.setDriverId(123);
    		viewTrip.setDrivingLicenseNumber("asd");
    		
    		//List list = new ArrayList();
    		//list.add(viewTrip); 
    		 json = new Gson().toJson(list);
    		
		 return list; 
    }
}